package com.info.zhiduoduo.weixin.controller;

import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.RepeatSubmitVerify;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseListFormBean;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.core.formbean.CheckProjectAmountFormBean;
import com.info.zhiduoduo.core.formbean.ProjectCheckFormBean;
import com.info.zhiduoduo.core.service.CoreProjectService;
import com.info.zhiduoduo.repository.dto.maker.MakerZddprojectBidDto;
import com.info.zhiduoduo.repository.dto.project.*;
import com.info.zhiduoduo.repository.entity.company.CompanyAccount;
import com.info.zhiduoduo.repository.entity.company.CompanyProject;
import com.info.zhiduoduo.weixin.formbean.company.BatchPublishProjectFormBean;
import com.info.zhiduoduo.weixin.formbean.project.*;
import com.info.zhiduoduo.weixin.service.ProjectService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/project")
public class ProjectController extends CommonController {

	@Autowired
	ProjectService projectService;
	@Autowired
	CoreProjectService coreProjectService;
//
//	/**
//	 创客 项目列表
//	 */
//	@PostMapping("/v1/projectForUser")
//	public SmartResult projectForUser(@RequestBody BaseSimpleFormBean<QueryProjectFormBean> baseSimpleFormBean) {
//		return projectService.queryUserProject(baseSimpleFormBean);
//	}
//
//	/**
//	 企业 项目列表
//	 */
//	@PostMapping("/v1/projectForCompany")
//	public SmartResult projectForCompany(@RequestBody BaseSimpleFormBean<QueryProjectFormBean> baseSimpleFormBean) {
//		return projectService.queryCompanyProject(baseSimpleFormBean);
//	}
//
//	@ApiOperation("获取企业创客的历史发单项目,支持分页")
//	@PostMapping("/v1/companyUserProject")
//	public SmartResult<ProjectBriefDto> projectForCompanyUser(@RequestBody BaseSimpleFormBean<QueryCompanyUserProjectFormBean> formBean) {
//		return projectService.queryCompanyUserProject(formBean);
//	}
//
//	/**
//	 发布项目 检索创客列表
//	 */
//	@PostMapping("/v1/queryUser")
//	public SmartResult queryUser(@RequestBody BaseSimpleFormBean<QueryUserFormBean> baseSimpleFormBean) {
//		return projectService.queryUserForPublishProject(baseSimpleFormBean);
//	}
//
//	@ApiOperation("批量创建项目草稿，但不发布项目")
//	@PostMapping("/batchPublish")
//	public SmartResult batchPublishProject(@RequestBody BaseListFormBean<BatchPublishProjectFormBean> formBean) {
//		return projectService.batchPublishProject(formBean);
//	}
//
//	@ApiOperation("编辑项目草稿")
//	@PostMapping("/editDraft")
//	public SmartResult editProjectDraft(@RequestBody BaseSimpleFormBean<EditProjectDraftFormBean> formBean) {
//		return projectService.editProjectDraft(formBean);
//	}
//
//	@PostMapping("/deleteDraft")
//	public SmartResult deleteProjectDraft(@RequestBody BaseSimpleFormBean<String> formBean) {
//		return projectService.deleteProjectDraft(formBean);
//	}
//
//	@ApiOperation("提交草稿项目并发布项目")
//	@ZddLog(type = ZddLogType.CREATE, name = "企业微信端提交项目草稿")
//	@PostMapping("/submitDraft")
//	public SmartResult submitDraft(@RequestBody BaseSimpleFormBean<SubmitDraftFormBean> formBean) {
//		return projectService.submitDraft(formBean);
//	}
//
//	/**
//	 企业 发布项目
//	 */
//	@ZddLog(name = "企业发布或更新项目")
//	@PostMapping("/v1/publishOrUpdateProject")
//	@RepeatSubmitVerify(expireSeconds = 5)
//	public SmartResult publishOrUpdateProject(@RequestBody BaseSimpleFormBean<PublishProjectFormBean> baseSimpleFormBean) {
//		return projectService.publishProject(baseSimpleFormBean);
//	}

	/**
	 * 企业发布项目前，检查是否超过季度或年度高金额预警，并计算预估服务费，税费。
	 */
	@PostMapping("/v1/checkCompanyUserAmount")
	public SmartResult<CheckProjectAmountDto> checkProjectAmount(@RequestBody BaseSimpleFormBean<CheckProjectAmountFormBean> formBean) {
		return coreProjectService.checkCompanyUserTotalAmount(formBean);
	}

	/**
	 * 创客提交验收项目前，检查季度或年度高金额预警，并计算预估服务费，税费
	 */
	@PostMapping("/v1/checkUserAmount")
	public SmartResult<AlertUserProjectAmountDto> checkUserAmount(@RequestBody BaseSimpleFormBean<CheckProjectAmountFormBean> formBean) {
		return coreProjectService.checkUserTotalAmount(formBean);
	}
//
//	/**
//	 项目详情
//	 */
//	@PostMapping("/v1/getProjectDetail")
//	public SmartResult getProjectDetail(@RequestBody BaseSimpleFormBean<ProjectIdFormBean> baseSimpleFormBean) {
//		return projectService.getProjectDetail(baseSimpleFormBean);
//	}
//
//	/**
//	 项目验收
//	 */
//	@ZddLog(type = ZddLogType.QUERY,name = "项目验收")
//	@PostMapping("/v1/projectCheck")
//	public SmartResult projectCheck(@RequestBody BaseSimpleFormBean<ProjectCheckFormBean> baseSimpleFormBean) {
//		return projectService.projectCheck(baseSimpleFormBean);
//	}
//
//	/**
//	 用户完成项目,通知验收
//	 */
//	@ZddLog(type = ZddLogType.UPDATE,name = "用户完成项目,通知验收",entities = @LogEntity(entity = CompanyProject.class,parameters =
//	@LogParameter(fields = "projectid",parameters = "formBean.reqdata.projectid")))
//	@PostMapping("/v1/userNotifyCheck")
//	public SmartResult userNotifyCheck(@RequestBody BaseSimpleFormBean<UserNotifyCheckFormBean> formBean) {
//		return projectService.userNotifyCheck(formBean);
//	}

	/**
	 根据tagid查询所有创客
	 */
	@PostMapping("/v1/queryUserByField")
	public SmartResult queryUserByTag(@RequestBody BaseSimpleFormBean<QueryUserByFieldFormBean> formBean) {
		return projectService.queryUserByField(formBean);
	}

	/**
	 获取创客详情
	 */
	@PostMapping("/v1/userInfo")
	public SmartResult getUserInfo(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return projectService.getUserInfo(formBean);
	}

	@ApiOperation("获取项目模板")
	@PostMapping("/getProjectCategoryAndTemplate")
	public SmartResult getProjectCategoryAndTemplate(@RequestBody BaseSimpleFormBean formBean) {
		return projectService.getProjectCategoryAndTemplate(formBean);
	}

//	@ApiOperation("获取创客上一个项目信息")
//	@PostMapping("/userLastProject")
//	public SmartResult<ProjectDto> getUserLastProject(@RequestBody BaseSimpleFormBean<String> formBean) {
//		return coreProjectService.getUserLastProject(formBean);
//	}
//
//	@ZddLog(type = ZddLogType.UPDATE, name = "上传 项目证据链")
//	@ApiOperation("上传 项目证据链")
//	@PostMapping("/uploadProjectFileUrl")
//	public SmartResult uploadProjectFileUrl(@RequestBody BaseSimpleFormBean<UploadProjectFileUrlFormBean> formBean) {
//		return projectService.uploadProjectFileUrl(formBean);
//	}
//
//	@ZddLog(type = ZddLogType.CREATE, name = "企业批量生成 项目交付物")
//	@ApiOperation("批量生成 交付文档")
//	@PostMapping("/generateProjectDeliveryFile")
//	public SmartResult generateProjectDeliveryFile(@RequestBody BaseSimpleFormBean<GenerateProjectAcceptance> formBean){
//		return projectService.generateProjectDeliveryFile(formBean.getUserid(), formBean.getReqdata());
//	}
//
//	@ApiOperation("下载 /众包项目验收压缩文件")
//	@GetMapping("/downloadProjectDeliveryZipFile")
//	public void downloadProjectDeliveryZipFile(HttpServletResponse response,
//											   @RequestParam("compid") int compid,
//											   @RequestParam("projectType") int projectType,
//											   @RequestParam("templateType") int templateType,
//											   @RequestParam("projectIdList") List<Integer> projectIdList) {
//		projectService.downloadProjectDeliveryZipFile(response, compid, projectType, templateType, projectIdList);
//	}
//
//	@ApiOperation("获取招标池中的项目")
//	@PostMapping("/listProjectBidPoolForUser")
//	public SmartResult<UserProjectDto> listProjectBidPoolForUser(@RequestBody BaseSimpleFormBean<ProjectBidPoolFormBean> formBean) {
//		return projectService.listProjectBidPoolForUser(formBean);
//	}
//
//	@ApiOperation("获取项目的创客竞标列表")
//	@PostMapping("/listMakerBids")
//	public SmartResult<MakerZddprojectBidDto> listMakerBids(@RequestBody  BaseSimpleFormBean<Integer> formBean) {
//		return projectService.listMakerBids(formBean);
//	}
//
//	@ApiOperation("创客竞标项目")
//	@PostMapping("/bidProject")
//	public SmartResult bidProject(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		return projectService.bidProject(formBean);
//	}
//
//	@ApiOperation("审核创客竞标")
//	@PostMapping("/verifyMakerBid")
//	public SmartResult verifyMakerBid(@Valid @RequestBody BaseSimpleFormBean<VerifyMakerBidFormBean> formBean) {
//		return projectService.verifyMakerBid(formBean);
//	}
//
//	/**
//	 * 取消项目，还未验收的项目都可以取消 2/24新加
//	 *
//	 * @param formBean
//	 * @return
//	 */
//	@ZddLog(type = ZddLogType.UPDATE,name = "取消项目",entities = @LogEntity(entity = CompanyAccount.class,parameters =
//	@LogParameter(fields = "projectid",parameters = "formBean.reqdata")))
//	@PostMapping("/cancel")
//	public SmartResult cancelProject(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		return projectService.cancelProject(formBean);
//	}
//
//	@ApiOperation(" /智众包发相同单检测")
//	@PostMapping("/checkSameProject")
//	public SmartResult<SameProjectDto> checkSameProject(@RequestBody BaseSimpleFormBean<CheckSameProjectFormBean> formBean) {
//		return projectService.checkSameProject(formBean);
//	}
//
//	@ApiOperation("企业一键生成（ /智众包/智零工/创客团）项目交付物")
//	@PostMapping("/generalAllDelivery")
//	public SmartResult generalAllDelivery(@RequestBody BaseSimpleFormBean formBean) {
//		return projectService.generalAllDelivery(formBean.getUserid());
//	}
}
